
import config from '@/config.js';

const baseUrl = config.BASE_URL;


const request = (type = '', data = {}, url = '', headers) => {
	let header = {}
	if (headers && typeof headers === 'string') {
		header['Content-Type'] = (headers == 'form') ? 'application/x-www-form-urlencoded' : headers
	} else {
		header = { ...headers }
	}
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: baseUrl + url,
			data: data,
			header,
			dataType: 'json',
			timeout: 60 * 1000,
		}).then((response) => {
			resolve(response.data);
		}).catch(error => {
			resolve(error);
		})
	});
}

export default request;
